<%--
  Created by IntelliJ IDEA.
  User: chris
  Date: 17/5/5
  Time: 下午12:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>劳务价格导入</title>
    <script type="text/javascript" src="<%=path %>/js/jquery/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="<%=path %>/js/jquery/jquery-form.js"></script>
    <script type="text/javascript">
        //ajax 方式上传文件操作
        <%--$(document).ready(function(){--%>
            <%--$('#btn').click(function(){--%>

                <%--if(checkData()){--%>

                    <%--$('#form1').ajaxSubmit({--%>
                        <%--url:'<%=path %>/laborPriceImport/upload',--%>
                        <%--dataType: 'text',--%>
                        <%--success: resutlMsg,--%>
                        <%--error: errorMsg--%>
                    <%--});--%>
                    <%--function resutlMsg(msg){--%>
                        <%--alert(msg);--%>
                        <%--$("#upfile").val("");--%>
                    <%--}--%>
                    <%--function errorMsg(){--%>
                        <%--alert("导入excel出错！");--%>
                    <%--}--%>
                <%--}--%>
            <%--});--%>
        <%--});--%>

        function doUpload() {
            if(checkData()) {
                var formData = new FormData($("#uploadForm")[0]);
                $.ajax({
                    url: '<%=path %>/laborPriceImport/upload',
                    type: 'POST',
                    data: formData,
                    dataType:"text",
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (returndata) {
//                        if (returndata = 'success')
                        alert('导入成功');
                    },
                    error: function (returndata) {
                        alert('导入excel出错！');
                    }
                });
            }
            }
        //JS校验form表单信息
        function checkData(){
            var fileDir = $("#upfile").val();
            var suffix = fileDir.substr(fileDir.lastIndexOf("."));
            if("" == fileDir){
                alert("选择需要导入的Excel文件！");
                return false;
            }
            if(".xlsx" != suffix ){
                alert("选择.xlsx格式的文件导入！");
                return false;
            }
            return true;
        }


    </script>
</head>
<body>
<legend class='hyc-legend'>
    <span>劳务价格导入</span>
</legend>

<div class="row hyc-query-row">
    <div class="col-md-1 text-right top7">第一步</div>
</div>
<div class="row hyc-query-row">
    <div class="col-md-4 text-right top7">下载价格导入模板，批量导入价格调整信息</div>
    <div class="col-md-1">
        <div class="form-group text-left">
            <%--<div class="btn btn-default btn-sm btn-warning" ng-click="loadData('query')">模板下载</div>&nbsp;&nbsp;&nbsp;--%>
            <a href="<%=path %>/laborPriceImport/download">模版下载</a>
        </div>
    </div>
</div>
<div class="row hyc-query-row">
    <div class="col-md-1 text-right top7">第二步</div>
</div>
<div class="row hyc-query-row">
    <div class="col-md-4 text-right top7">上传填写好的价格调整信息表</div>
    <!--<div class="col-md-1">-->
    <!--<div class="form-group text-left">-->
    <!--<input type="file" data-ng-model="file" />-->
    <!--</div>-->
    <!--</div>-->
</div>
<form method="POST"  enctype="multipart/form-data" id="uploadForm" action="<%=path %>/laborPriceImport/upload">
    <table>
        <tr>
            <td>上传文件: </td>
            <td> <input id="upfile" type="file" name="upfile"></td>
        </tr>
        <tr>
            <%--<td><input type="submit" value="提交" onclick="return checkData()"></td>--%>
            <td><input type="button" value="导入" id="btn" name="btn" onclick="doUpload()"></td>
        </tr>
    </table>
</form>
</body>
</html>
